<?php

namespace app\admin\model;

use app\lib\Qiniu;

use app\admin\model\Image;

class Villages extends Base
{

    public static function _after_delete($id){
        if(is_array($id)){
            $list = Image::where('relatedTable', 'Product')->whereIn('relatedId', $id)->select();
        }else{
            $list = Image::where('relatedTable', 'Product')->where('relatedId', $id)->select();
        }

        $Qiniu = new Qiniu();
        foreach ((array)$list as $v) {
            $key = substr(strrchr($v['imgUrl'], '/'), 1);
            // 删除七牛图片
            $res = $Qiniu->delImg($key);

            Image::where('id', $v['id'])->delete();
        }
    }

    /**
     * 根据条件得到 select options
     */
    /*public static function makeOptions($where, $field = '', $order = [])
    {
        $options = [];
        $results = Villages::where($where)->field($field)->order($order)->select();
        foreach ($results as $result) {
            $options[$result->id] = $result->name;
        }

        return $options;
    }*/
}
